package com.ctshk.app.system.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.system.dto.MainDataTouristTypeListDTO;
import com.ctshk.rpc.system.req.*;
import com.ctshk.rpc.system.service.IMainDataTouristTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *
 * </p>
 *
 * @author xuhui
 * @since 1/25/2021
 */
@Api(value = "旅客类型", tags = "主数据旅客类型")
@RestController
@RequestMapping("/main/data/tourist/type")
public class MainDataTouristTypeController extends BaseController {
    @DubboReference
    IMainDataTouristTypeService mainDataTouristTypeService;


    @ApiResponses({ @ApiResponse(code = 0, message ="成功") })
    @ApiOperation(value="旅客类型列表", notes="查询旅客类型主数据列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "搜索旅客类型", operDesc = "搜索旅客类型主数据")
    @PostMapping("/list")
    public Result<PageResponse<MainDataTouristTypeListDTO>> listTouristType(@RequestBody @Valid MainDataTouristTypeListReq req){
        PageResponse<MainDataTouristTypeListDTO> list = mainDataTouristTypeService.list(req);
        return Result.success(list);
    }

    @ApiOperation(value="查询旅客类型", notes="查询旅客类型主数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "搜索旅客类型", operDesc = "搜索旅客类型主数据")
    @PostMapping("/query")
    public Result<MainDataTouristTypeListDTO> query(@RequestBody @Valid MainDataTouristTypeQueryReq req){
        MainDataTouristTypeListDTO dto = mainDataTouristTypeService.query(req);
        return Result.success(dto);
    }

    @ApiOperation(value="增加旅客类型", notes="增加旅客类型主数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "增加旅客类型", operDesc = "增加旅客类型主数据")
    @PostMapping("/add")
    public Result<Integer> addTouristType(@RequestBody @Valid MainDataTouristTypeAddReq mainDataPassengerTypeReq){

        TokenUser currentUser = getCurrentUser(getRequest());
        return  mainDataTouristTypeService.add(mainDataPassengerTypeReq,currentUser);
    }

    @ApiOperation(value="编辑旅客类型", notes="编辑旅客类型主数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "编辑旅客类型", operDesc = "编辑旅客类型主数据")
    @PostMapping("/modify")
    public Result<Integer> modifyTouristType(@RequestBody @Valid MainDataTouristTypeModifyReq mainDataTouristTypeModifyReq){
        TokenUser currentUser = getCurrentUser(getRequest());
        return mainDataTouristTypeService.modify(mainDataTouristTypeModifyReq,currentUser);

    }

    @ApiOperation(value="编辑旅客类型状态", notes="编辑旅客类型状态主数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "编辑旅客类型状态", operDesc = "编辑旅客类型状态主数据")
    @PostMapping("/modify/status")
    public Result<Integer> modifyTouristTypeStatus(@RequestBody @Valid MainDataTouristTypeModifyStatusReq mainDataTouristTypeModifyStatusReq){
        TokenUser currentUser = getCurrentUser(getRequest());
        return mainDataTouristTypeService.modifyStatus(mainDataTouristTypeModifyStatusReq,currentUser);

    }

    @ApiOperation(value="删除旅客类型", notes="删除旅客类型主数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.DELETE, operTitle = "删除旅客类型", operDesc = "删除旅客类型主数据")
    @GetMapping("/delete/{id}")
    public Result<Integer> deleteTouristType(@PathVariable Long id){
        TokenUser currentUser = getCurrentUser(getRequest());
        return mainDataTouristTypeService.delete(id,currentUser);
    }

}